﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache" content="no-cache" />
    <title>排班周期</title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js?v=@DateTime.Now.ToString("yyyyMMdd")"></script>
</head>
<body>
    <div class="searchbar">        
        <div class="sbligerButton">
            <input id="btnAdd" type="button" value="新增" class="l-button" />
        </div>
        <div class="sbligerButton">
            <input id="btnSearch" type="button" value="刷新" class="l-button" />
        </div>
    </div>
    <div id="maingrid"></div>
    <script type="text/javascript">
        $(function () {
            $('#btnSearch').click(function () {
                search(1);
            });
            $("#btnAdd").click(function () {
                edit(0);
            })
            $('#btnSearch').click();
        });
        //查询功能
        function search(pageNumber) {
            var queryData = { }
            initTable(queryData, pageNumber);
        }
        //显示表数据
        var grid;
        function initTable(queryData, pageNumber) {
            grid = $("#maingrid").ligerGrid({
                checkbox: false,
                height: '100%',
                //data: {
                //    "Total": 3, "Rows": [
                //        { "ID": 1, "TypeName": "周", "Enabled": 1, "Sort": "3" },
                //        { "ID": 2, "TypeName": "双周", "Enabled": 0, "Sort": "2" },
                //        { "ID": 3, "TypeName": "月", "Enabled": 0, "Sort": "1" }
                //    ]
                //},
                url: '/Scheduling/ScheduleCycle/Search?ram=' + new Date().getMilliseconds(),
                parms: queryData,
                page: pageNumber,
                pageSize: 30,
                rownumbers: false,
                heightDiff: -5,
                usePager: true,
                columns: [
        { display: '排班周期', name: 'TypeName', minWidth: 50, width: 150 },
        { display: '排序', name: 'Sort', minWidth: 50, width: 150 },
        {
            display: '状态', name: 'Enabled', minWidth: 50, width: 150,
            render: function (rowData) {                 
                return rowData.Enabled == 1 ?
                    "<span onclick=\"enabled(" + rowData.Id+ ")\" style=\"cursor:pointer;color:green;\">启用</span>" :
                    "<span onclick=\"enabled(" + rowData.Id + ")\" style=\"cursor:pointer;\" >禁用</span>";
            }
        },
        {
            display: '操作', name: '', minWidth: 50, width: 200,
            render: function (rowData) {
                return "<a style=\"cursor:pointer;\" class=\"a-edit\" onclick=\"edit(" + rowData.Id + ")\" >编辑</a> | <a style=\"cursor:pointer;\" class=\"a-edit\" onclick=\"enabled(" + rowData.Id + ")\" >" + (rowData.Enabled == 1 ? "禁用" : "启用") + "</a> | <a style=\"cursor:pointer;\" class=\"a-del\" onclick=\"del(" + rowData.Id + ")\" >删除</a>";
            }
        }],
                isScroll: true,
                onSuccess: function (data, grid) {
                }
            });
        }
        function edit(id) {
            var tit = id > 0 ? "编辑排班" : "新增排班";
            $.ligerDialog.open({
                height: 245,
                width: 420,
                title: tit, 
                url: '/Scheduling/ScheduleCycle/Edit?id=' + id,
                showMax: false,
                showToggle: false,
                showMin: false,
                isResize: false,
                slide: false,
                data: {},
                buttons: [{
                    text: '回调函数', onclick: function (i, d) {
                        $("#btnSearch").click();
                    }
                }],
                cls: "closeCls"
            }).max();
            $(".l-dialog-buttons").hide();
        }
        function enabled(id) {
            var url = "/Scheduling/ScheduleCycle/Enabled?ram=" + Math.random();
            $.post(url, {
                rnd: new Date().getMilliseconds(),
                Id: id
            }, function (data, textStatus) {
                if (textStatus == "success") {
                    var d = $.parseJSON(data);
                    if (d.Result == 1) {
                        search(1);
                        $.ligerDialog.success("操作成功");
                    }
                    else if (d.Result == 0) {
                        $.ligerDialog.error(d.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                } else { $.ligerDialog.error("程序错误"); }
            });
        }
        function del(id) {
            $.ligerDialog.confirm('确定删除？', function (yes) {
                if (yes) {
                    var editurl = "/Scheduling/ScheduleCycle/Delete?ram=" + Math.random();
                    $.post(editurl, {
                        rnd: new Date().getMilliseconds(),
                        Id: id
                    }, function (data, textStatus) {
                        if (textStatus == "success") {
                            var d = $.parseJSON(data);
                            if (d.Result == 1) {
                                search(1);
                                $.ligerDialog.success("删除成功");
                            }
                            else if (d.Result == 0) {
                                $.ligerDialog.error(d.Body);
                            }
                            else {
                                $.ligerDialog.error("程序错误");
                            }
                        } else { $.ligerDialog.error("程序错误"); }
                    });
                }
            });
        }
        $(document).on("click", ".closeCls", function () {
            search(1);
        });
    </script>
</body>
</html>